package cn.itsource.order.controller;


import cn.itsource.basic.util.AxajResult;
import cn.itsource.basic.util.SystemLoginInfo;
import cn.itsource.order.service.IAdoptOrderService;
import cn.itsource.user.domain.LoginInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 领养订单Controller
 */
@RestController
@RequestMapping("/adopt")
public class AdoptOrderController {

    @Autowired
    private IAdoptOrderService adoptOrderService;

    /**
     * 提交订单
     * @param  map  (addressId(用户地址id)  payType(支付方式)  petId(宠物id))
     * @return
     */
    @PostMapping("/submitOrder")
    public AxajResult submitOrder(@RequestBody Map<String,Object> map, HttpServletRequest request){
        try {
            LoginInfo loginInfo = SystemLoginInfo.get(request);
            //提交订单(返回支付宝接口的字符串html代码)
            String result = adoptOrderService.submitOrder(map, loginInfo);
            return new AxajResult().setObjResult(result);
        } catch (Exception e) {
            e.printStackTrace();
            return new AxajResult(false, e.getMessage());
        }
    }
}
